import { app } from 'electron';
import path from 'node:path'
import { PythonShell } from 'python-shell'
import log from 'electron-log/main';
// import robot from 'robotjs';

// 执行python脚本

const pythonPath = path.join(path.dirname(app.getPath('exe')), 'python/Scripts/python.exe');
const scriptPath = path.join(process.resourcesPath, 'assets/scripts')

/**
 * 每隔1s
 * 使用robotjs获取鼠标的坐标
 * 使用python-shell执行python脚本，传递参数（坐标），获取坐标位置的控件的xpath
 */


// 一次调用
const options = {
  pythonPath,
  pythonOptions: ['-u'],
  scriptPath,
  args: ['100', '200']
}

PythonShell.run('my_script.py', options).then(results => {
  // results is an array consisting of messages collected during execution
  log.info('results: %j', results);
});

// 交换数据
{
  let pyshell = new PythonShell('my_script.py', options);

  // sends a message to the Python script via stdin
  pyshell.send('hello');

  pyshell.on('message', function (message) {
    // received a message sent from the Python script (a simple "print" statement)
    console.log(message);
  });

  // end the input stream and allow the process to exit
  pyshell.end(function (err, code, signal) {
    if (err) throw err;
    console.log('The exit code was: ' + code);
    console.log('The exit signal was: ' + signal);
    console.log('finished');
  });
}
